package com.bharatonjava.swift.service;

import java.util.List;

import javax.transaction.Transactional;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.bharatonjava.swift.dao.IRoleDao;
import com.bharatonjava.swift.dao.IUserDao;
import com.bharatonjava.swift.domain.Role;
import com.bharatonjava.swift.domain.User;

@Service
public class UserService {

	private static final Log log = LogFactory.getLog(UserService.class);
	private IUserDao userDao;
	private IRoleDao roleDao;
	
	public UserService() {
	}
	
	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}
	
	public void setRoleDao(IRoleDao roleDao) {
		this.roleDao = roleDao;
	}
	
	@Transactional
	public List<User> getAllUsers(){
		List<User> users = userDao.getAllUsers();
		System.out.println(users);
		return users;
	}
	
	@Transactional
	public List<Role> getAllRoles(){
		List<Role> roles = roleDao.getAllRoles();
		return roles;
	}
	
	@Transactional
	public void addUser(User user){
		log.info(user);
		userDao.addUser(user);
	}
	
	@Transactional
	public boolean userExists(User user) {
		return userDao.userExists(user);
	}
}
